package com.modelo.dao.asalariado;

import java.util.List;

import org.hibernate.LockMode;
import org.hibernate.SessionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.modelo.dao.comun.HibernateBaseDAO;
import com.modelo.entity.Asalariado;
import com.modelo.entity.Documento;

@Repository
public class AsalariadoDAO extends HibernateBaseDAO<Asalariado> implements IAsalariadoDAO {
	private static final Logger log = LoggerFactory
			.getLogger(AsalariadoDAO.class);
 
	public static final String NOMBRE = "nombre";
	public static final String DNI = "dni";
	public static final String APELLIDOS = "apellidos";

	protected void initDao() {
		 
	}
	
	 @Autowired  
	 public AsalariadoDAO(SessionFactory sessionFactory) {  
	        super(sessionFactory);  
	 }

	public List<Asalariado> findByExample(Asalariado instance) {
		log.debug("finding Asalariado instance by example");
		try {
			List<Asalariado> results = (List<Asalariado>) getHibernateTemplate()
					.findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Asalariado instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Asalariado as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List<Asalariado> findByNombre(Object nombre) {
		return findByProperty(NOMBRE, nombre);
	}

	public List<Asalariado> findByDni(Object dni) {
		return findByProperty(DNI, dni);
	}

	public List<Asalariado> findByApellidos(Object apellidos) {
		return findByProperty(APELLIDOS, apellidos);
	}

	public static AsalariadoDAO getFromApplicationContext(ApplicationContext ctx) {
		return (AsalariadoDAO) ctx.getBean("AsalariadoDAO");
	}
}